﻿namespace OasisCiq.Xprl
{
    using System.Collections.Generic;
    using System.Xml;
    using System.Xml.Schema;
    using System.Xml.Serialization;
    using Xml;

    /// <summary>
    /// A Party (could be individual (person or organisation) or a group) 
    /// that is in relationship with another party and 
    /// could be individual (person or organisation) or a group)
    /// </summary>
    public class PartyType : Xpil.PartyType
    {
        private static readonly XmlQualifiedName XmlElementName =
            new XmlQualifiedName("Party", XmlNamespaces.PartyRelationships);

        public virtual ICollection<Relationship> AdvancedRelationships { get; set; }

        public override void ReadXml(XmlReader reader)
        {
            var wrapper = XmlUtilities.Wrap(reader);
            if (XmlUtilities.MoveToElement(wrapper, XmlElementName))
            {
                new XprlXmlReader(wrapper).ReadParty(
                    this,
                    XmlElementName.Name,
                    XmlElementName.Namespace);
            }
        }

        public override void WriteXml(XmlWriter writer)
        {
            new XprlXmlWriter(writer).WriteParty(this);
        }
    }
}
